#!/bin/sh

source scripts/common.sh

mkdir -p ${THIRD_PARTY_BUILD}
pushd ${THIRD_PARTY_BUILD}

QGLV_VERSION=2.3.4
QGLV_BASENAME="libQGLViewer"
QGLV_ARCHIVE="libQGLViewer-${QGLV_VERSION}.tar.gz"
QGLV_DIR="libQGLViewer-${QGLV_VERSION}"
QGLV_URL="http://www.libqglviewer.com/src/${QGLV_ARCHIVE}"

echo "Removing old build from '${QGLV_DIR}'..."
rm -fr $QGLV_DIR

echo "Preparing tarball '${QGLV_ARCHIVE}'..."
fetch $QGLV_URL $QGLV_ARCHIVE

echo "Configuring '${QGLV_BASENAME}'..."
pushd ${QGLV_DIR} || exit 1
pushd QGLViewer || exit 1
${THIRD_PARTY_QT_DIR}/bin/qmake "CONFIG += x86 ppc x86_64" QGLVIEWER_STATIC="1" QT_VERSION="4.6.2" PREFIX=${THIRD_PARTY_PREFIX}/${QGLV_BASENAME} || exit 

if test $? -ne 0; then
        echo "configure failed"
        exit 1
fi

echo "Stripping legacy Qt3 usage..."

sed -i".bak" '/qPixmapFromMimeSource/ s/qPixmapFromMimeSource/ /' VRenderInterface.Qt4.ui 

echo "Building '${QGLV_ARCHIVE}'..."
nice make -j4 || exit 1
nice make install || exit 1

popd
popd
popd